package com.itheima.reggie.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.reggie.pojo.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 既白
 */
public interface ShoppingCartDao extends BaseMapper<ShoppingCart> {
    @Insert("insert into shopping_cart values(null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void add(ShoppingCart shoppingCart);

    /**
     * 通过dishId或setmealId查询购物车项是否存在
     */
    ShoppingCart findCartItem(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id= #{userId}")
    List<ShoppingCart> findCartItemByUserId(Long userId);

    @Delete("delete from shopping_cart where user_id= #{userId}")
    void deleteCartItemByUserId(Long userId);

    @Update("update shopping_cart set `number`=#{number} where id=#{id}")
    void updatNumber(ShoppingCart shoppingCart);

    @Update("update shopping_cart set `number`=#{number} where id=#{id}")
    void subNumber(ShoppingCart shoppingCart);
}
